# -*- coding: utf-8 -*-
import random
import sys
import time
from PySide6.QtCore import *
from PySide6.QtWidgets import *


class BackQthread(QThread):
    # 自定义信号为str参数类型
    update_date = Signal(str)

    def run(self):
        while True:
            # 获得当前系统时间
            data = QDateTime.currentDateTime()
            # 设置时间显示格式
            current_time = data.toString('yyyy-MM-dd hh:mm:ss dddd')
            # 发射信号
            self.update_date.emit(str(current_time))
            print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
            t = random.randint(1, 100)
            if t > 50:
                print("goods_config.json and hero_config.json")
                time.sleep(3)
            else:
                print("hero_config.json")
            print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")


class window(QDialog):
    def __init__(self):
        super(window, self).__init__()
        self.okColor = "49, 54, 59"
        self.okBackgrundColor = "29, 233, 182"
        self.errColor = "255, 255, 255"
        self.errBackgrundColor = "70, 119, 255"
        self.workColer = '30, 39, 46'
        self.workBackgrundColor = '254, 211, 48'
        self.style = None
        self.backend = None
        self.backend2 = None
        self.setWindowTitle('PyQt5界面实时更新的例子')
        self.resize(400, 100)
        self.lable = QLabel(self)
        self.lable.resize(400, 100)
        self.lable2 = QLabel(self)
        self.lable2.resize(400, 100)
        layout = QVBoxLayout()
        layout.addWidget(self.lable)
        layout.addWidget(self.lable2)
        self.setLayout(layout)
        self.init_ui()

    def init_ui(self):
        self.style = 'QLabel{color: rgb(%s);background-color: rgb(%s);}' \
                     % (self.workColer, self.workBackgrundColor)
        # 实例化对象
        self.backend = BackQthread()
        # 信号连接到界面显示槽函数
        self.backend.update_date.connect(self.handle_display)
        # 多线程开始
        self.backend.start()

        self.backend2 = BackQthread()
        # 信号连接到界面显示槽函数
        self.backend2.update_date.connect(self.handle_display2)
        # 多线程开始
        self.backend2.start()

    def handle_display(self, data):
        # 设置单行文本框的文本
        print('handle_display1111111')
        self.lable.setText(data)
        self.lable.setStyleSheet(self.style)

    def handle_display2(self, data):
        print('handle_display2222222')
        self.lable2.setText(data)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = window()
    win.show()
    sys.exit(app.exec())
